<!-- 计划 -->
<template>
	<el-drawer v-model="isShowDrawer" direction="rtl" :before-close="handleClose" :size="curDrawerSize" :close-on-click-modal="true">
		<template #header="{ titleId, titleClass }">
			<div class="zs-drawer-header" :id="titleId" :class="titleClass">
				<i class="icon-b-item zs-icon zs-text-blue zs-space-right-sm"></i>
				<div class="zs-title zs-text-black">同步</div>
			</div>
		</template>

		<template #default>
			<el-container class="zs-drawer-container">
				<el-scrollbar class="zs-drawer-content">
					<div class="zs-card zs-space-bottom">
						<el-form label-position="right" label-width="70px" :model="formData">
							<el-form-item label="月份：">
								<el-date-picker v-model="formData.yearMonth" type="month" style="width: 100%" value-format="YYYY-MM" />
							</el-form-item>
						</el-form>
					</div>
				</el-scrollbar>
				<hsDocWrapper :nodeList="curNodeList" />
			</el-container>
		</template>
		<template #footer>
			<div>
				<el-button class="zs-btn-md zs-btn-primary" @click="doConfirm">提交</el-button>
			</div>
		</template>
	</el-drawer>
</template>

<script setup>
	import { ref, reactive, watch } from 'vue';
	import { useStore } from 'vuex';
	import { staffSyncData } from '@/api/residence.js';
	import { ElMessage } from 'element-plus';

	const props = defineProps({
		isShow: { type: Boolean, default: false },
		handleType: { type: String, default: '' },
		currentRow: { type: Object },
	});

	watch(
		() => props.isShow,
		newVal => {
			isShowDrawer.value = newVal;
			formData.yearMonth = '';
		},
	);

	let store = useStore();
	const curDrawerSize = ref(store.state.uiDrawerSize);

	let formData = reactive({ yearMonth: '' });

	const emit = defineEmits(['close']);

	let isShowDrawer = ref(props.isShow);
	const curNodeList = ref([{ name: '月份', id: 'sm-drawer-demo-card-01' }]);

	//提交
	const doConfirm = async () => {
		let res = await staffSyncData({ projectCode: props.currentRow.projectCode, yearMonth: formData.yearMonth, type: props.currentRow.type });
		if (res.data.code == 200) {
			ElMessage({ message: '同步成功', type: 'success' });
			emit('close', { isShow: false, isRefresh: true });
		}
	};

	//关闭抽屉
	const handleClose = done => {
		emit('close', { isShow: false });
		done();
	};
</script>
